home *** CD-ROM | disk | FTP | other *** search
/ The Atari Compendium / The Atari Compendium (Toad Computers) (1994).iso / files / prgtools / mint / mntdoc01.zoo / mintdoc / cat2 / fcntl.nr < prev    next >
Encoding:
Text File  |  1993-03-03  |  17.1 KB  |  463 lines

  1.  
  2.  
  3.  
  4. Fcntl(2)                  July 20, 1992                  Fcntl(2)
  5.  
  6.  
  7. N✓NA✓AM✓ME✓E
  8.        Fcntl - perform various control operations on a file
  9.  
  10. S✓SY✓YN✓NO✓OP✓PS✓SI✓IS✓S
  11.        #include <filesys.h>
  12.  
  13.        LONG Fcntl( WORD fh, LONG arg, WORD cmd);
  14.  
  15. D✓DE✓ES✓SC✓CR✓RI✓IP✓PT✓TI✓IO✓ON✓N
  16.        _✓F_✓c_✓n_✓t_✓l performs various control operations on the open file
  17.        with GEMDOS file handle _✓f_✓h.  The specific command to  per-
  18.        form  is  given by _✓c_✓m_✓d; the possible commands are given by
  19.        symbolic constants in filesys.h,  and  are  listed  below.
  20.        _✓a_✓r_✓g is an argument whose meaning depends on the command.
  21.  
  22.        The following commands are applicable to any file descrip-
  23.        tor:
  24.  
  25.        F_DUPFD
  26.               Return a duplicate for the  file  handle.  The  new
  27.               (duplicate)  handle will be an integer >= arg and <
  28.               32. If no free handles exist in that range,  ENHNDL
  29.               will  be  returned.  The  _✓F_✓d_✓u_✓p(_✓f_✓h)  system  call is
  30.               equivalent to _✓F_✓c_✓n_✓t_✓l(_✓f_✓h, 6L, F_DUPFD)
  31.  
  32.        F_GETFD
  33.               Return the noinherit flag for the file  descriptor.
  34.               This  flag is 0 if child processes started by _✓P_✓e_✓x_✓e_✓c
  35.               should inherit this open file, and 1 if they should
  36.               not.  _✓a_✓r_✓g is ignored.
  37.  
  38.        F_SETFD
  39.               Set the noinherit flag for the file descriptor from
  40.               the low order bit of _✓a_✓r_✓g.  The default value of the
  41.               flag  is 0 for handles 0-5 (the "standard" handles)
  42.               and 1 for other (non-standard) handles.  Note  that
  43.               the  noinherit flag applies only to this particular
  44.               file descriptor; another descriptor  obtained  from
  45.               _✓f_✓h by the _✓F_✓d_✓u_✓p system call or by use of the F_DUPFD
  46.               option to _✓F_✓c_✓n_✓t_✓l will have the noinherit flag set to
  47.               the  default. Also note that these defaults are not
  48.               the same as for the Unix operating system.
  49.  
  50.        F_GETFL
  51.               Returns the user-settable  file  descriptor  flags.
  52.               These  flags  are  the  same  as the mode passed to
  53.               _✓F_✓o_✓p_✓e_✓n, unless they have been  further  modified  by
  54.               another _✓F_✓c_✓n_✓t_✓l operation.  _✓a_✓r_✓g is ignored.
  55.  
  56.        F_SETFL
  57.               Set  user-settable  file  descriptor flags from the
  58.               argument _✓a_✓r_✓g.  Only the user-settable bits  in  _✓a_✓r_✓g
  59.               are  considered;  the  settings  of  other bits are
  60.               ignored, but should be 0 for future  compatibility.
  61.  
  62.  
  63.  
  64. Version 0.95         MiNT Programmer's Manual                   1
  65.  
  66.  
  67.  
  68.  
  69.  
  70. Fcntl(2)                  July 20, 1992                  Fcntl(2)
  71.  
  72.  
  73.               Moreover,  it  is  not  possible to change a file's
  74.               read-write mode or sharing modes  with  this  call;
  75.               attempts to do so will (silently) fail.
  76.  
  77.        F_GETLK
  78.               _✓a_✓r_✓g is a pointer to an flock structure:
  79.               struct flock {
  80.                    short l_type;  /* type of lock */
  81.               #define F_RDLCK          0
  82.               #define F_WRLCK          1
  83.               #define F_UNLCK          3
  84.                    short l_whence;     /* 0:file start, 1:current, 2:EOF */
  85.                    long l_start;  /* offset of locked region */
  86.                    long l_len;    /* 0 for rest of file */
  87.                    short l_pid;   /* set by F_GETLK */
  88.               };
  89.               If a lock exists which would prevent this lock from
  90.               being applied to the file,  the  existing  lock  is
  91.               copied  into  the  structure and the l_pid field is
  92.               set to the process id of the locking process.  Oth-
  93.               erwise,  l_type is set to F_UNLCK. If a conflicting
  94.               lock is held by a process on a different machine on
  95.               a  network,  then  the l_pid field will be set to a
  96.               value defined by  the  network  file  system.  This
  97.               value  will  be  in the range 0x1000 to 0xFFFF, and
  98.               will therefore not conflict  with  any  process  id
  99.               since process id's must be less than 0x1000.
  100.  
  101.        F_SETLK
  102.               Set  (if l_type is F_RDLCK or F_WRLCK) or clear (if
  103.               l_type is F_UNLCK) an advisory lock on a  file.  If
  104.               the  file  is a FIFO, the whole file must be locked
  105.               or unlocked at once, i.e.  l_whence,  l_start,  and
  106.               l_len must be 0. If this lock would conflict with a
  107.               lock held by another process, ELOCKED is  returned.
  108.               If an attempt is made to clear a non-existent lock,
  109.               ENSLOCK is returned. More than one read lock may be
  110.               placed  on  the same region of a file, but no write
  111.               lock may overlap with any other sort of lock.  If a
  112.               process  holds  locks on a file, then the locks are
  113.               automatically released whenever the process  closes
  114.               an open file handle referring to that file, or when
  115.               the process terminates.
  116.  
  117.        FSTAT  _✓a_✓r_✓g points to an XATTR structure, which  is  filled
  118.               in  with  the  appropriate extended file attributes
  119.               for the file to which _✓f_✓d refers just as though  the
  120.               _✓F_✓x_✓a_✓t_✓t_✓r  system  call  (q.v.)  had  been made on the
  121.               file.
  122.  
  123.        FIONREAD
  124.               _✓a_✓r_✓g points to a 32 bit integer, into which is writ-
  125.               ten  the  number of bytes that are currently avail-
  126.               able to be read from this  descriptor;  a  read  of
  127.  
  128.  
  129.  
  130. Version 0.95         MiNT Programmer's Manual                   2
  131.  
  132.  
  133.  
  134.  
  135.  
  136. Fcntl(2)                  July 20, 1992                  Fcntl(2)
  137.  
  138.  
  139.               this  number  of bytes or less should not cause the
  140.               process to block (wait for more input).  Note  that
  141.               for some files only an estimate can be provided, so
  142.               the number is not always completely accurate.
  143.  
  144.        FIONWRITE
  145.               _✓a_✓r_✓g points to a 32 bit integer, into which is writ-
  146.               ten  the number of bytes that may be written to the
  147.               indicated file descriptor without causing the  pro-
  148.               cess  to  block.   Note that for some files only an
  149.               estimate can be provided,  so  the  number  is  not
  150.               always completely accurate.
  151.  
  152.        The  following commands are valid for any terminal device,
  153.        e.g. the console or a pseudo-terminal:
  154.  
  155.        TIOCGETP
  156.               Get terminal parameters.  _✓a_✓r_✓g is  a  pointer  to  a
  157.               block of memory with the following structure:
  158.               struct sgttyb {
  159.                    char sg_ispeed;          /* reserved */
  160.                    char sg_ospeed;          /* reserved */
  161.                    char sg_erase;      /* erase character */
  162.                    char sg_kill;       /* line kill character */
  163.                    short sg_flags;          /* terminal control flags */
  164.               };
  165.  
  166.        TIOCSETP
  167.               Set  terminal  parameters  from  the  struct sgttyb
  168.               pointed to by _✓a_✓r_✓g.
  169.  
  170.        TIOCGETC
  171.               Get terminal control characters.  _✓a_✓r_✓g is a  pointer
  172.               to the following structure:
  173.               struct tchars {
  174.                    char t_intrc;  /* raises SIGINT */
  175.                    char t_quitc;  /* raises SIGQUIT */
  176.                    char t_startc; /* starts terminal output */
  177.                    char t_stopc;  /* stops terminal output */
  178.                    char t_eofc;   /* marks end of file */
  179.                    char t_brkc;   /* marks end of line */
  180.               };
  181.  
  182.        TIOCSETC
  183.               Set  terminal  control  characters  from the struct
  184.               tchars pointed to by _✓a_✓r_✓g.  Setting any character to
  185.               the  value  0  causes the corresponding function to
  186.               become unavailable.
  187.  
  188.        TIOCGLTC
  189.               Get extended terminal control characters,  and  put
  190.               them in the structure pointed to by _✓a_✓r_✓g:
  191.               struct ltchars {
  192.                    char t_suspc;  /* raises SIGTSTP now */
  193.  
  194.  
  195.  
  196. Version 0.95         MiNT Programmer's Manual                   3
  197.  
  198.  
  199.  
  200.  
  201.  
  202. Fcntl(2)                  July 20, 1992                  Fcntl(2)
  203.  
  204.  
  205.                    char t_dsuspc; /* raises SIGTSTP when read */
  206.                    char t_rprntc; /* redraws the input line */
  207.                    char t_flushc; /* flushes output */
  208.                    char t_werasc; /* erases a word */
  209.                    char t_lnextc; /* quotes a character */
  210.               };
  211.  
  212.        TIOCSLTC
  213.               Set  extended  terminal control characters from the
  214.               struct ltchars pointed to by _✓a_✓r_✓g.  Setting  any  of
  215.               the  characters to 0 causes the corresponding func-
  216.               tion to become unavailable.
  217.  
  218.        TIOCGWINSZ
  219.               _✓a_✓r_✓g has type "struct winsize *". The current window
  220.               size  for  this  window  is placed in the structure
  221.               pointed to by _✓a_✓r_✓g, which has the following fields:
  222.               struct winsize {
  223.                    short     ws_row;   /* # of rows of text in window*/
  224.                    short     ws_col;   /* # of columns of text */
  225.                    short     ws_xpixel; /* width of window in pixels */
  226.                    short     ws_ypixel; /* height of window in pixels */
  227.               };
  228.               If any fields in the structure are  0,  this  means
  229.               that the corresponding value is unknown.
  230.  
  231.        TIOCSWINSZ
  232.               _✓a_✓r_✓g has type "struct winsize *". The current window
  233.               size for the  window  is  set  from  the  structure
  234.               pointed  to by _✓a_✓r_✓g.  Note that the kernel maintains
  235.               the information but does n✓no✓ot✓t act  upon  it  in  any
  236.               way;  it  is up to window managers to perform what-
  237.               ever physical changes are necessary  to  alter  the
  238.               window  size,  and  to raise the SIGWINCH signal if
  239.               necessary.
  240.  
  241.        TIOCGPGRP
  242.               _✓a_✓r_✓g has type "long *"; the process  group  for  the
  243.               terminal  is placed into the long pointed to by it.
  244.  
  245.        TIOCSPGRP
  246.               _✓a_✓r_✓g has type "long *"; the process  group  for  the
  247.               terminal  is  set  from  the long pointed to by it.
  248.               Processes in any other process group will  be  sent
  249.               job control signals if they attempt input or output
  250.               to the terminal.
  251.  
  252.        TIOCSTART
  253.               Restart output to the terminal (as though the  user
  254.               typed  control-Q)  if it was stopped by a control-S
  255.               or TIOCSTOP command.  _✓a_✓r_✓g is ignored.
  256.  
  257.        TIOCSTOP
  258.               Stop output to the terminal  (as  though  the  user
  259.  
  260.  
  261.  
  262. Version 0.95         MiNT Programmer's Manual                   4
  263.  
  264.  
  265.  
  266.  
  267.  
  268. Fcntl(2)                  July 20, 1992                  Fcntl(2)
  269.  
  270.  
  271.               typed control-S).  _✓a_✓r_✓g is ignored.
  272.  
  273.        TIOCGXKEY
  274.               Get  the  definition  of  a function or cursor key.
  275.               _✓a_✓r_✓g is a pointer to a structure with the  following
  276.               fields:
  277.               struct xkey {
  278.                    short     xk_num;      /* function key number */
  279.                    char xk_def[8]; /* associated string */
  280.               };
  281.               The  _✓x_✓k_✓__✓n_✓u_✓m field must be initialized with the num-
  282.               ber of the desired key:
  283.                 xk_num   Key
  284.                  0-9         F1-F10
  285.                 10-19        F11-F20 (shift F1-shift F10)
  286.                  20          cursor up
  287.                  21          cursor down
  288.                  22          cursor right
  289.                  23          cursor left
  290.                  24          help
  291.                  25          undo
  292.                  26          insert
  293.                  27          clr/home
  294.                  28          shift+cursor up
  295.                  29          shift+cursor down
  296.                  30          shift+cursor right
  297.                  31          shift+cursor left
  298.               The string currently associated with the  indicated
  299.               key  is  copied  into xk_def; this string is always
  300.               null-terminated.
  301.  
  302.        TIOCSXKEY
  303.               _✓a_✓r_✓g is a structure of type struct xkey, as  defined
  304.               above.  Both  the _✓x_✓k_✓__✓n_✓u_✓m and the _✓x_✓k_✓__✓d_✓e_✓f fields must
  305.               be defined. After execution of this command, and if
  306.               the  XKEY  bit  is set in the _✓s_✓g_✓__✓f_✓l_✓a_✓g_✓s field of the
  307.               sgttyb structure associated with the terminal, then
  308.               if  the  indicated  key  is pressed on the affected
  309.               terminal, any MiNT domain process  using  _✓F_✓r_✓e_✓a_✓d  to
  310.               read  the key will get the string in _✓x_✓k_✓__✓d_✓e_✓f instead
  311.               of ASCII 0. Note that this translation occurs  only
  312.               for  MiNT  domain  processes and only for the _✓F_✓r_✓e_✓a_✓d
  313.               system call. Also note that the  string  in  _✓x_✓k_✓__✓d_✓e_✓f
  314.               must  be  null terminated, and so at most 7 charac-
  315.               ters may be assigned to any key.
  316.  
  317.  
  318.        The following commands are valid only for processes opened
  319.        as files:
  320.  
  321.        PBASEADDR
  322.               _✓a_✓r_✓g  is  a  pointer to a 32 bit integer, into which
  323.               the address of the process basepage for the process
  324.               to which _✓f_✓h refers is written.
  325.  
  326.  
  327.  
  328. Version 0.95         MiNT Programmer's Manual                   5
  329.  
  330.  
  331.  
  332.  
  333.  
  334. Fcntl(2)                  July 20, 1992                  Fcntl(2)
  335.  
  336.  
  337.        PPROCADDR
  338.               _✓a_✓r_✓g  is  a  pointer to a 32 bit integer, into which
  339.               the address of the process  control  structure  for
  340.               the  process  is  written.  Note  that this control
  341.               structure differs from the one  found  in  previous
  342.               versions  (before  0.93)  of  MiNT;  it  no  longer
  343.               includes the process context, so that this part  of
  344.               the  structure  may be changed without causing com-
  345.               patibility problems. See the _✓P_✓C_✓T_✓X_✓T_✓S_✓I_✓Z_✓E command.
  346.  
  347.        PCTXTSIZE
  348.               _✓a_✓r_✓g is a pointer to a 32 bit  integer,  into  which
  349.               the  length of a process context structure is writ-
  350.               ten. There are two of these structures  located  in
  351.               memory  just  before  the process control structure
  352.               whose address is returned by the _✓P_✓P_✓R_✓O_✓C_✓A_✓D_✓D_✓R command.
  353.               The  first is the current process context; the sec-
  354.               ond is the saved context from the last system call.
  355.  
  356.  
  357.        The following commands are valid only for files which rep-
  358.        resent shared memory.
  359.  
  360.        SHMSETBLK
  361.               _✓a_✓r_✓g is a pointer to a block  of  memory  previously
  362.               allocated  by  _✓M_✓x_✓a_✓l_✓l_✓o_✓c.  The memory will be offered
  363.               for sharing under the name of the file  represented
  364.               by _✓f_✓d (which must be a file in the U:\SHM subdirec-
  365.               tory).
  366.  
  367.        SHMGETBLK
  368.               _✓a_✓r_✓g must be 0, for  future  compatibility.  Returns
  369.               the address of the block of memory previously asso-
  370.               ciated with the  file  via  _✓S_✓H_✓M_✓S_✓E_✓T_✓B_✓L_✓K,  or  a  NULL
  371.               pointer  if  an  error occurs.  Note that different
  372.               processes may see the shared memory block  at  dif-
  373.               ferent  addresses  in  their address spaces. There-
  374.               fore, the shared memory block  should  not  contain
  375.               any absolute pointers to data.
  376.  
  377.  
  378. R✓RE✓ET✓TU✓UR✓RN✓NS✓S
  379.        0  or  a positive number if successful (for most commands;
  380.        but see the specific descriptions above).
  381.  
  382.        EIHNDL if _✓f_✓h is not a valid GEMDOS open handle.
  383.  
  384.        EINVFN if the specified command is not valid for this file
  385.        handle
  386.  
  387.        Some  other  (LONG)  negative  error  number  if  an error
  388.        occurs; different commands may recognize different  possi-
  389.        ble errors.
  390.  
  391.  
  392.  
  393.  
  394. Version 0.95         MiNT Programmer's Manual                   6
  395.  
  396.  
  397.  
  398.  
  399.  
  400. Fcntl(2)                  July 20, 1992                  Fcntl(2)
  401.  
  402.  
  403. S✓SE✓EE✓E A✓AL✓LS✓SO✓O
  404.        _✓F_✓d_✓u_✓p(2),   _✓F_✓l_✓o_✓c_✓k(2),   _✓F_✓o_✓p_✓e_✓n(2),  _✓F_✓x_✓a_✓t_✓t_✓r(2),  _✓P_✓g_✓e_✓t_✓p_✓g_✓r_✓p(2),
  405.        _✓P_✓s_✓e_✓t_✓p_✓g_✓r_✓p(2)
  406.  
  407.  
  408. B✓BU✓UG✓GS✓S
  409.        Very little error checking is done. In particular,  owner-
  410.        ship   of  terminals  is  not  properly  checked,  nor  is
  411.        read/write access to the files. Do not rely on  this  bug;
  412.        it will be fixed some day.
  413.  
  414.        File locking is not yet implemented for most file systems.
  415.  
  416.        Very few of the terminal control options  have  effect  on
  417.        terminals  connected via serial ports or midi. In particu-
  418.        lar, it is not possible to set the baud rate, parity, flow
  419.        control, or similar options with _✓F_✓c_✓n_✓t_✓l.  However, this bug
  420.        will be fixed in future versions of the operating  system,
  421.        so  programs should never modify the sg_ispeed, sg_ospeed,
  422.        or sg_flags fields of the  sgttyb  structure,  and  should
  423.        always  use  TIOCGETP  to  obtain the original settings of
  424.        these fields before calling TIOCSETP.
  425.  
  426.  
  427.  
  428.  
  429.  
  430.  
  431.  
  432.  
  433.  
  434.  
  435.  
  436.  
  437.  
  438.  
  439.  
  440.  
  441.  
  442.  
  443.  
  444.  
  445.  
  446.  
  447.  
  448.  
  449.  
  450.  
  451.  
  452.  
  453.  
  454.  
  455.  
  456.  
  457.  
  458.  
  459.  
  460. Version 0.95         MiNT Programmer's Manual                   7
  461.  
  462.  
  463.